/**
 * 作废弹窗
 */
/**
 * 补充计划量
 * @author xiaoxujs
 */

import { Input, message, Modal } from "antd";
import { FC, useState } from "react";
import { postPlanCancel } from "../../../api";

const { TextArea } = Input;

const ToVoidModule: FC<{
    open: boolean;
    handleCallback: () => void;
    clickId?: string
}> = ({
    open,
    handleCallback,
    clickId
}) => {
        const [cancelReason, setCancelReason] = useState<string>(''); //作废原因
        const handleOk = async () => {
            if (clickId) {
                if(cancelReason === '') {
                    message.warning('请填写作废原因')
                }else{
                    const params = {
                        id: clickId,
                        cancelReason: cancelReason
                    }
                    const { code, msg } = await postPlanCancel(params) as { code: number, msg: string };
                    if (code === 20000) {
                        message.success('作废成功');
                        setCancelReason('');
                        handleCallback();
                    } else {
                        message.error(msg);
                    }
                }
              
            }


        };

        const handleCancel = () => {
            setCancelReason('');
            handleCallback()
        };
        return <Modal title="作废原因" open={open} onOk={handleOk} onCancel={handleCancel}>
            <TextArea rows={4} value={cancelReason} onChange={(e) => setCancelReason(e.target.value)} />
        </Modal>
    }

export default ToVoidModule;